package com.example.pkmedical.Activity.rollovershock;

import android.os.Bundle;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextClock;
import android.widget.TextView;

import androidx.fragment.app.FragmentTransaction;


import com.example.pkmedical.Base.BaseActivity;
import com.example.pkmedical.Fragments.shock.ShockCustomizedFragment;
import com.example.pkmedical.Fragments.shock.ShockHighFragment;
import com.example.pkmedical.Fragments.shock.ShockLowFragment;
import com.example.pkmedical.Fragments.shock.ShockSecondaryFragment;
import com.example.pkmedical.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ShockActivity extends BaseActivity {
    @BindView(R.id.main_house)
    ImageView mainHouse;
    @BindView(R.id.top_icon_layout)
    RelativeLayout topIconLayout;
    @BindView(R.id.main_house_text)
    TextView mainHouseText;
    @BindView(R.id.main_date)
    TextClock mainDate;
    @BindView(R.id.shock_high)
    TextView shockHigh;
    @BindView(R.id.shock_secondary)
    TextView shockSecondary;
    @BindView(R.id.shock_low)
    TextView shockLow;
    @BindView(R.id.shock_customized)
    TextView shockCustomized;
    @BindView(R.id.shock_framelayout)
    FrameLayout shockFramelayout;
    ShockHighFragment shockHighFragment;
    ShockSecondaryFragment shockSecondaryFragment;
    ShockLowFragment shockLowFragment;
    ShockCustomizedFragment shockCustomizedFragment;
    @BindView(R.id.shock_bottom_goback)
    TextView shockBottomGoback;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shock_main);
        ButterKnife.bind(this);
    }

    @Override
    public void initData() {

    }

    @Override
    public void initView() {
        mainHouse.setImageResource(R.drawable.img_title_fbzl);
        mainHouseText.setText(R.string.title_bar_qjzd);
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        hideAllFragment(transaction);
        high_on();
        if (shockHighFragment == null) {
            shockHighFragment = new ShockHighFragment();
            transaction.add(R.id.shock_framelayout, shockHighFragment);
        } else {
            transaction.show(shockHighFragment);
        }
        transaction.commit();
    }

    @Override
    public void initPresenter() {

    }

    @Override
    public void showDialog(String... msg) {

    }

    public void hideAllFragment(FragmentTransaction transaction) {
        if (shockHighFragment != null) {
            transaction.hide(shockHighFragment);
        }
        if (shockSecondaryFragment != null) {
            transaction.hide(shockSecondaryFragment);
        }
        if (shockLowFragment != null) {
            transaction.hide(shockLowFragment);
        }
        if (shockCustomizedFragment != null) {
            transaction.hide(shockCustomizedFragment);
        }
    }

    private void high_on() {


        shockHigh.setBackgroundResource(R.drawable.changgui_item_back_on);
        shockHigh.setTextColor(getResources().getColor(R.color.green_back_text));
        shockSecondary.setBackgroundResource(R.drawable.changgui_item_back_off);
        shockSecondary.setTextColor(getResources().getColor(R.color.white));
        shockLow.setBackgroundResource(R.drawable.changgui_item_back_off);
        shockLow.setTextColor(getResources().getColor(R.color.white));
        shockCustomized.setBackgroundResource(R.drawable.changgui_item_back_off);
        shockCustomized.setTextColor(getResources().getColor(R.color.white));
    }

    private void secondary_on() {


        shockHigh.setBackgroundResource(R.drawable.changgui_item_back_off);
        shockHigh.setTextColor(getResources().getColor(R.color.white));
        shockSecondary.setBackgroundResource(R.drawable.changgui_item_back_on);
        shockSecondary.setTextColor(getResources().getColor(R.color.green_back_text));
        shockLow.setBackgroundResource(R.drawable.changgui_item_back_off);
        shockLow.setBackgroundResource(R.drawable.changgui_item_back_off);
        shockLow.setTextColor(getResources().getColor(R.color.white));
        shockCustomized.setBackgroundResource(R.drawable.changgui_item_back_off);
        shockCustomized.setTextColor(getResources().getColor(R.color.white));
    }

    private void low_on() {
        shockHigh.setBackgroundResource(R.drawable.changgui_item_back_off);
        shockHigh.setTextColor(getResources().getColor(R.color.white));
        shockSecondary.setBackgroundResource(R.drawable.changgui_item_back_off);
        shockSecondary.setTextColor(getResources().getColor(R.color.white));
        shockLow.setBackgroundResource(R.drawable.changgui_item_back_on);
        shockLow.setTextColor(getResources().getColor(R.color.green_back_text));
        shockCustomized.setBackgroundResource(R.drawable.changgui_item_back_off);
        shockCustomized.setTextColor(getResources().getColor(R.color.white));
    }

    private void customized_on() {
        shockHigh.setBackgroundResource(R.drawable.changgui_item_back_off);
        shockHigh.setTextColor(getResources().getColor(R.color.white));
        shockSecondary.setBackgroundResource(R.drawable.changgui_item_back_off);
        shockSecondary.setTextColor(getResources().getColor(R.color.white));
        shockLow.setBackgroundResource(R.drawable.changgui_item_back_off);
        shockLow.setTextColor(getResources().getColor(R.color.white));
        shockCustomized.setBackgroundResource(R.drawable.changgui_item_back_on);
        shockCustomized.setTextColor(getResources().getColor(R.color.green_back_text));
    }

    @OnClick({R.id.shock_high, R.id.shock_secondary, R.id.shock_low, R.id.shock_customized, R.id.shock_bottom_goback})
    public void onViewClicked(View view) {
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        hideAllFragment(transaction);
        switch (view.getId()) {
            case R.id.shock_high:
                high_on();
                if (shockHighFragment == null) {
                    shockHighFragment = new ShockHighFragment();
                    transaction.add(R.id.shock_framelayout, shockHighFragment);
                } else {
                    transaction.show(shockHighFragment);
                }
                break;
            case R.id.shock_secondary:
                secondary_on();
                if (shockSecondaryFragment == null) {
                    shockSecondaryFragment = new ShockSecondaryFragment();
                    transaction.add(R.id.shock_framelayout, shockSecondaryFragment);
                } else {
                    transaction.show(shockSecondaryFragment);
                }
                break;
            case R.id.shock_low:
                low_on();
                if (shockLowFragment == null) {
                    shockLowFragment = new ShockLowFragment();
                    transaction.add(R.id.shock_framelayout, shockLowFragment);
                } else {
                    transaction.show(shockLowFragment);
                }
                break;
            case R.id.shock_customized:
                customized_on();
                if (shockCustomizedFragment == null) {
                    shockCustomizedFragment = new ShockCustomizedFragment();
                    transaction.add(R.id.shock_framelayout, shockCustomizedFragment);
                } else {
                    transaction.show(shockCustomizedFragment);
                }
                break;
            case R.id.shock_bottom_goback:
                finish();
//                overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
                break;
        }
        transaction.commit();
    }
}
